<template>
	<view>
		<button @click="registerEvent">registerEvent</button>
		<button @click="unregisterEvent">unregisterEvent</button>
		
		<button @click="sendEvent">sendEvent</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		methods: {
			onTestEvent(data) {
				console.log("onTestEvent...", JSON.stringify(data))
				uni.showToast({
					icon:"none",
					title:"data:" + JSON.stringify(data)
				})
			},
			registerEvent() {
				//也可在页面onLoad中注册，在unload中解注册
				uni.$on("testEvent", this.onTestEvent)
			},
			unregisterEvent() {
				uni.$off("testEvent", this.onTestEvent)
			},
			sendEvent() {
				uni.$emit("testEvent", {"test": "haha"})
			}
		}
	}
</script>

<style>

</style>
